//
//  SLCertificationItemComponent.m
//  SulitLoanDemo
//
//  Created by 虞嘉伟 on 2025/2/20.
//  
  

#import "SLCertificationItemComponent.h"
#import <YYKit.h>
#import <Masonry.h>

@interface SLCertificationItemComponent ()
@property (nonatomic, strong) UIStackView *stackView;
@property (nonatomic, strong) UIView *rightView;
@end
@implementation SLCertificationItemComponent


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.stackView];
        [self.stackView addArrangedSubview:self.bgView];
        [self.stackView addArrangedSubview:self.rightView];
        
        [self.bgView addSubview:self.indexLabel];
        [self.bgView addSubview:self.icon];
        [self.bgView addSubview:self.titleLabel];
        [self.rightView addSubview:self.arrow];
        [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(self.stackView);
        }];
        [self.rightView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(50);
            make.height.equalTo(self.stackView);
        }];
        [self.indexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgView).offset(15);
            make.centerY.equalTo(self.bgView);
        }];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.indexLabel.mas_right).offset(10);
            make.top.bottom.equalTo(self.bgView);
        }];
        [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bgView).inset(10);
            make.bottom.equalTo(self.bgView);
            make.width.mas_equalTo(63);
            make.height.mas_equalTo(44);
        }];
        [self.arrow mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(20);
            make.center.equalTo(self.rightView);
        }];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
}


- (void)setIsComplete:(BOOL)isComplete {
    _isComplete = isComplete;
    self.rightView.hidden = isComplete;
}



- (UIStackView *)stackView {
    if (!_stackView) {
        _stackView = [UIStackView new];
    }
    return _stackView;
}
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = UIColor.whiteColor;
        _bgView.layer.borderColor = UIColorHex(#1B1B1B).CGColor;
        _bgView.layer.borderWidth = 1.5;
        _bgView.layer.cornerRadius = 20;
    }
    return _bgView;
}
- (UILabel *)indexLabel {
    if (!_indexLabel) {
        _indexLabel = [UILabel new];
        _indexLabel.textColor = UIColorHex(#666666);
        _indexLabel.font = [UIFont fontWithName:@"Rammetto One" size:14];
        _indexLabel.text = @"1";
        _indexLabel.numberOfLines = 0;
    }
    return _indexLabel;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textColor = UIColorHex(#666666);
        _titleLabel.font = aspectDefaultFont(14);
        _titleLabel.text = @"Identity document + face authentication";
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}
- (UIImageView *)icon {
    if (!_icon) {
        _icon = [UIImageView new];
        _icon.contentMode = UIViewContentModeScaleAspectFit;
        _icon.transform = CGAffineTransformRotate(CGAffineTransformIdentity, 60);
    }
    return _icon;
}
- (UIView *)rightView {
    if (!_rightView) {
        _rightView = [UIView new];
    }
    return _rightView;
}
- (UIImageView *)arrow {
    if (!_arrow) {
        _arrow = [UIImageView new];
        _arrow.contentMode = UIViewContentModeScaleAspectFit;
        _arrow.image = [UIImage imageNamed:@"icon_down_arrow"];
    }
    return _arrow;
}
@end
